/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.com.barrientosjunior.massfilerenamer.parser;

import br.com.barrientosjunior.massfilerenamer.parser.element.Element;
import br.com.barrientosjunior.massfilerenamer.parser.element.ContTagElement;

/**
 *
 * @author Junior
 */
public class ContTagParser{

    public ContTagElement parse(PatternParser parentParser, String pattern, int index) throws Exception {
        ContTagElement tagContElement = null;
        try {
            index += 6;
            char c = pattern.charAt(index);
            String snum = "";
            do {
                snum = snum + c;
                index++;
                c = pattern.charAt(index);
            } while (c != ']');
            index++;
            int charsNum = Integer.parseInt(snum);

            tagContElement = new ContTagElement(charsNum);

            //change the PatternsParser's char search index, so it doesnt try to read "[cont" again.
            parentParser.setI(index);
        } catch (Exception e) {
            throw new Exception("Erro no parse da tag CONT do padrão inserido.");
        }
        return tagContElement;
    }

}
